package com.yunchao.bank

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.tencent.mmkv.MMKV
import com.yunchao.bank.BuildConfig
import com.yunchao.bank.business.businessModules
import com.yunchao.bank.configure.configureModules
import com.yunchao.bank.main.mainModules
import com.yunchao.bank.splash.splashModule
import com.yunchao.feature.base.baseModule
import com.yunchao.feature.base.domain.utils.FileLoggingTree
import com.yunchao.feature.lock.featureLockModules
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext
import timber.log.Timber

class HFEDApplication : Application() {

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this)
        initKoin()
        initTimber()
    }

    private fun initKoin() {
        GlobalContext.startKoin {
            androidLogger()
            androidContext(this@HFEDApplication)
            modules(baseModule)
            modules(appModule)
            modules(featureLockModules)
            modules(configureModules)
            modules(mainModules)
            modules(businessModules)
            modules(splashModule)
        }
    }

    private fun initTimber() {
        Timber.plant(if (BuildConfig.DEBUG) Timber.DebugTree() else FileLoggingTree(this))
    }
}